﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BrokentLineList : MonoBehaviour {

    private Toggle filter;//滤波

    private ToggleGroup togG;//成组
    private Transform m_Content;//父物体
    private int m_MaxCount;

	void Start () {
        filter = transform.Find( "DataPanel/Toggle" ).GetComponent<Toggle>();
        filter.onValueChanged.AddListener( Filter );

        togG = transform.Find("DataPanel/Scroll View/Viewport/Content").GetComponent<ToggleGroup>();
        m_Content = transform.Find( "DataPanel/Scroll View/Viewport/Content" );
    }

   

    // Update is called once per frame
    void Update () {
		
	}
    /// <summary>
    /// 增加
    /// </summary>
    /// <param name="count"></param>
    /// <param name="lst"></param>
    void AddOrDecList(int count,List<uint> lst) {
        if (m_Content.childCount < count) {
            for (int i = 0; i < count; i++) {
                if (i >= m_Content.childCount) {
                    GameObject go = Instantiate( Resources.Load( "Prefabs/BrokenLineID" ) ) as GameObject;
                    go.transform.SetParent( m_Content );
                    go.transform.localScale = Vector3.one;              
                    go.transform.GetComponent<Toggle>().group = togG;
                    go.GetComponent<Toggle>().isOn = false;                    
                }
            }
        }
        //添加文字
        for (int i = 0; i < m_Content.childCount; i++) {
            m_Content.GetChild( i ).GetComponentInChildren<Text>().text = lst[i].ToString();
            uint num = lst[i];
            m_Content.GetChild( i ).GetComponent<Toggle>().onValueChanged.AddListener( OnToggleClick );
            m_Content.GetChild( i ).name = num.ToString();
        }
    }
    /// <summary>
    /// 显示所有的Toggle
    /// </summary>
    /// <param name="lst"></param>
    public void ShowAllToggle(List<uint> lst) {
        m_MaxCount = lst.Count;
        AddOrDecList( m_MaxCount, lst );
    }
    /// <summary>
    /// 生成对应舟船折线图
    /// </summary>
    /// <param name="select"></param>
    private void OnToggleClick(bool select) {
        IEnumerable<Toggle> togGroup = togG.ActiveToggles();
        foreach(Toggle item in togGroup) {
            if (item.isOn) {
               
            }
        }
    }
    /// <summary>
    /// 滤波折线图
    /// </summary>
    /// <param name="b"></param>
    private void Filter(bool b) {

    }
}
